package websocket;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/websocket")
public class WebSocketTest {
	private Session sen;
	@OnOpen
	public void onOpen(Session sen){
		this.sen=sen;
		System.out.println("有连接加入。。。。。"+sen.getId());
	}
	@OnClose
	public void onClose(){
		System.out.println("有连接断开...."+sen.getId());
	}
	@OnMessage
	public void onMessage(String msg,Session sen) throws Exception{
		System.out.println("hello..."+msg);
		//响应
		sen.getBasicRemote().sendText("Hello:"+msg);
	}
	@OnError
	public void onError(Session sen,Throwable error){
		
	}
}
